﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace CooStationsToolsNew
{
    /// <summary>
    /// BusyIndicator.xaml 的交互逻辑
    /// </summary>
    public partial class BusyIndicator : Window
    {
        Window win;
        public BusyIndicator(Window _win)
        {
            InitializeComponent();
            win = _win;
        }
        private DispatcherTimer time = null;
        public static bool flag = false;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            time = new DispatcherTimer();
            time.Interval = new TimeSpan(0, 0, 0,0,200);
            time.Tick += new EventHandler(time_Elapsed);
            time.Start();
            Thread d = new Thread(new ThreadStart(RunBat));
            d.Start();
        }
      
        void time_Elapsed(object sender, EventArgs e)
        {
            if (flag)
            { time.Stop();
                flag = false;
                this.Close();
                MessageForm1 mf = new MessageForm1("编译成功");
                mf.Owner = win;
                mf.ShowDialog();
                string path = @"C:\cygwin\GooIOS\build\4.0";
                System.Diagnostics.Process.Start("explorer.exe", path);
                    //RunBat();
            }
        }
       
        public void RunBat()
        {
          IOSTools ios = new IOSTools();

          Process pro = new Process();
          //pro.Exited += new EventHandler(p_Exited);
          
           pro.StartInfo.FileName = @"C:\cygwin\CygwinRunGooIOS.bat";

          pro.StartInfo.UseShellExecute = false;
          pro.StartInfo.RedirectStandardOutput = true;
          pro.StartInfo.RedirectStandardInput = true;
          pro.StartInfo.CreateNoWindow = true;
          pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
          pro.Start();
          
         // MessageBox.Show(pro.StandardOutput.ReadToEnd());
          pro.WaitForExit();
          pro.Close();
          flag = true;
          // this.Close();
        }

        void p_Exited(object sender, EventArgs e)
        {
            flag = true;
        }

        
    }
}
